package com.moon.game.command.guest.mission;

import java.util.ArrayList;
import java.util.List;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.Constants;
import com.moon.game.exception.GException;
import com.moon.game.manager.MissionMG;
import com.moon.game.resource.model.Mission;
import com.moon.game.vos.PlayerVo;
import com.moon.game.vos.PlayerVo.MyMission;

/**
 * @description 查看我的任务
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-2 下午3:49:38
 */
public class ShowMyMissionsCmd extends BaseCmd {

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
			case STATU_INIT:
				doInit(req);
				break;
			case STATU_CHECK:
				doCheckSelf(req);
				break;
			case STATU_RETURN:
				doResponse(req);
				break;
			default:
				break;
		}

	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		Integer type = Integer.parseInt(ps[0]);
		if (type == null) {
			doResponsePsError(req);
			return;
		}
		
		req.setVO("cur_type", type);
		
		PlayerVo player = req.getPlayer();
		List<MyMission> myMissions = null;
		List<Integer> missionIds = new ArrayList<Integer>();
		if (type == Constants.MAIN_MISSION_TYPE) {
			//主线任务
			myMissions = player.getMainMissionList();
		}else if (type == Constants.DAILY_MISSION_TYPE) {
			//日常任务
			myMissions = player.getDailyMissionList();
		}
		if (myMissions != null) {
			for (MyMission myMission : myMissions) {
				Mission mission = MissionMG.instance.getMission(myMission.getMissionId());
				if (myMission.getStatu() == 1) {
					//日常任务处于完成状态
					continue;
				}
				if (mission != null && mission.getType() == type.intValue()) {
					missionIds.add(mission.getId());
				}
			}
		}
		
		req.setVO("mission_ids", missionIds);
		req.setVO("refresh_price", Constants.REFRESH_MISSION_PRICE);
		response(req, req.getClientResponse());
	}

}
